`:top
In `F33f`_`[computer programming`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Computer_programming]`_`f, a `!statement`! is a `F33f`_`[syntactic`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Syntax_(programming_languages)]`_`f unit of an `F33f`_`[imperative programming language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Imperative_programming]`_`f that expresses some action to be carried out.`:cite-ref-1[`F5bf`_`[1`#cite-note-1]`_`f] A `F33f`_`[program`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Computer_program]`_`f written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g. `F33f`_`[expressions`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Expression_(computer_science)]`_`f).
Many programming languages (e.g. `F33f`_`[Ada`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Ada_(programming_language)]`_`f, `F33f`_`[Algol 60`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Algol_60]`_`f, `F33f`_`[C`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=C_(programming_language)]`_`f, `F33f`_`[Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f, `F33f`_`[Pascal`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Pascal_(programming_language)]`_`f) make a distinction between statements and `F33f`_`[definitions/declarations`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Declaration_(computer_programming)]`_`f. A definition or declaration specifies the data on which a program is to operate, while a statement specifies the actions to be taken with that data.
Statements which cannot contain other statements are `*simple`*; those which can contain other statements are `*compound`*.`:cite-ref-algol60-2-0[`F5bf`_`[2`#cite-note-algol60-2]`_`f]
The appearance of a statement (and indeed a program) is determined by its `F33f`_`[syntax`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Syntax_(programming_languages)]`_`f or grammar. The meaning of a statement is determined by its `F33f`_`[semantics`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Semantics_(computer_science)]`_`f.
>>Contents
• `F0af`_`[Simple statements`#simple-statements]`_`f
• `F0af`_`[Compound statements`#compound-statements]`_`f
• `F0af`_`[Syntax`#syntax]`_`f
• `F0af`_`[Statements and keywords`#statements-and-keywords]`_`f
• `F0af`_`[Semantics`#semantics]`_`f
• `F0af`_`[Expressions`#expressions]`_`f
• `F0af`_`[Extensibility`#extensibility]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[External links`#external-links]`_`f
-─
>>Simple statements
Simple statements are complete in themselves; these include assignments, subroutine calls, and a few statements which may significantly affect the program flow of control (e.g. `F33f`_`[goto`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Goto]`_`f, `F33f`_`[return`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Return_statement]`_`f, stop/halt). In some languages, input and output, assertions, and exits are handled by special statements, while other languages use calls to predefined subroutines.
• `F33f`_`[assignment`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Assignment_(computer_science)]`_`f
• Fortran: `B100`F9d9`*variable`* = `*expression`*`f`b
• Pascal, Algol 60, Ada: `B100`F9d9`*variable`* := `*expression`*;`f`b
• C, C#, C++, PHP, Java: `B100`F9d9`*variable`* = `*expression`*;`f`b
• `F33f`_`[call`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Subroutine]`_`f
• Fortran: `B100`F9d9CALL `*subroutine name`*(`*parameters`*)`f`b
• C, C++, Java, PHP, Pascal, Ada: `B100`F9d9`*subroutine name`*(`*parameters`*);`f`b
• `F33f`_`[assertion`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Assertion_(software_development)]`_`f
• C, C++, PHP: `B100`F9d9assert(`*relational expression`*);`f`b
• Java: `B100`F9d9assert `*relational expression`*;`f`b
• `F33f`_`[goto`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=GOTO]`_`f
• Fortran: `B100`F9d9GOTO numbered-label`f`b
• Algol 60: `B100`F9d9`!goto`! `*label`*;`f`b
• C, C++, PHP, Pascal: `B100`F9d9goto `*label`*;`f`b
• `F33f`_`[return`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Return_statement]`_`f
• Fortran: `B100`F9d9RETURN `*value`*`f`b
• C, C++, Java, PHP: `B100`F9d9return `*value`*;`f`b
• `F33f`_`[stop/halt/exit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Exit_(system_call)]`_`f
• Fortran: `B100`F9d9STOP `*number`*`f`b
• C, C++: `B100`F9d9exit(`*expression`*)`f`b
• PHP: `B100`F9d9exit `*number`*;`f`b
>>Compound statements
Compound statements may contain (sequences of) statements, nestable to any reasonable depth, and generally involve tests to decide whether or not to obey or repeat these contained statements.
Notation for the following examples: <statement> is any single statement (could be simple or compound). <sequence> is any sequence of zero or more <statements> Some programming languages provide a general way of grouping statements together, so that any single <statement> can be replaced by a group:
Algol 60: `B100`F9d9`!begin`! <sequence> `!end`!`f`b Pascal: `B100`F9d9begin <sequence> end`f`b C, PHP, Java: `B100`F9d9{ <sequence> }`f`b
Other programming languages have a different special terminator on each kind of compound statement, so that one or more statements are automatically treated as a group: Ada: `B100`F9d9if test then <sequence> end if;`f`b
Many compound statements are loop commands or choice commands. In theory only one of each of these types of commands is required. In practice there are various special cases which occur quite often; these may make a program easier to understand, may make programming easier, and can often be implemented much more efficiently. There are many subtleties not mentioned here; see the linked articles for details.
• `F33f`_`[count-controlled loop`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=For_loop]`_`f:
• Algol 60: `B100`F9d9`!for`! index := 1 `!step`! 1 `!until`! limit `!do`! <statement> ;`f`b
• Pascal: `B100`F9d9for index := 1 to limit do <statement> ;`f`b
• C, Java: `B100`F9d9for ( index = 1; index <= limit; index += 1) <statement> ;`f`b
• Ada: `B100`F9d9for index in 1..limit loop <sequence> end loop`f`b
• Fortran 90:DO index = 1,limit <sequence> END DO
• `F33f`_`[condition-controlled loop`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=While_loop]`_`f with test at start of loop:
• Algol 60: `B100`F9d9`!for`! index := expression `!while`! test `!do`! <statement> ;`f`b
• Pascal: `B100`F9d9while test do <statement> ;`f`b
• C, Java: `B100`F9d9while (test) <statement> ;`f`b
• Ada: `B100`F9d9while test loop <sequence> end loop`f`b
• Fortran 90: DO WHILE (test) <sequence> END DO
• `F33f`_`[condition-controlled loop`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Do_while_loop]`_`f with test at end of loop:
• Pascal: `B100`F9d9repeat <sequence> until test; { note reversed test }`f`b
• C, Java: `B100`F9d9do { <sequence> } while (test) ;`f`b
• Ada: `B100`F9d9loop <sequence> exit when test; end loop;`f`b
• condition-controlled loop with test in the middle of the loop:
• C: `B100`F9d9do { <sequence> if (test) break; <sequence> } while (true) ;`f`b
• Ada: `B100`F9d9loop <sequence> exit when test; <sequence> end loop;`f`b
• `F33f`_`[if-statement`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Conditional_(programming)]`_`f simple situation:
• Algol 60:`B100`F9d9`!if`! test `!then`! <unconditional statement> ;`f`b
• Pascal: `B100`F9d9if test then <statement> ;`f`b
• C, Java: `B100`F9d9if (test) <statement> ;`f`b
• Ada: `B100`F9d9if test then <sequence> end if;`f`b
• Fortran 77+: IF (test) THEN <sequence> END IF
• `F33f`_`[if-statement`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Conditional_(programming)]`_`f two-way choice:
• Algol 60: `B100`F9d9`!if`! test `!then`! <unconditional statement> `!else`! <statement> ;`f`b
• Pascal: `B100`F9d9if test then <statement> else <statement> ;`f`b
• C, Java: `B100`F9d9if (test) <statement> else <statement> ;`f`b
• Ada: `B100`F9d9if test then <sequence> else <sequence> end if;`f`b
• Fortran 77+: IF (test) THEN <sequence> ELSE <sequence> END IF
• `F33f`_`[case/switch statement`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Switch_statement]`_`f multi-way choice:
• Pascal: `B100`F9d9case c of 'a': alert(); 'q': quit(); end;`f`b
• Ada: `B100`F9d9case c is when 'a' => alert(); when 'q' => quit(); end case;`f`b
• C, Java: `B100`F9d9switch (c) { case 'a': alert(); break; case 'q': quit(); break; }`f`b
• `F33f`_`[Exception handling`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Exception_handling]`_`f:
• Ada: `B100`F9d9begin `*protected code`* except when `*exception specification`* => `*exception handler`*`f`b
• Java: `B100`F9d9try { `*protected code`* } catch (`*exception specification`*) { `*exception handler`* } finally { `*cleanup`* }`f`b
• Python: `B100`F9d9 try: `*protected code`* except `*exception specification`*: `*exception handler`* else: `*no exceptions`* finally: `*cleanup`*`f`b
>>Syntax
Apart from assignments and subroutine calls, most languages start each statement with a special word (e.g. goto, if, while, etc.) as shown in the above examples. Various methods have been used to describe the form of statements in different languages; the more formal methods tend to be more precise:
• Algol 60 used `F33f`_`[Backus–Naur form`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Backus–Naur_form]`_`f (BNF) which set a new level for language grammar specification.`:cite-ref-algol60rpt-3-0[`F5bf`_`[3`#cite-note-algol60rpt-3]`_`f]
• Up until Fortran 77, the language was described in English prose with examples,`:cite-ref-fortran66-4-0[`F5bf`_`[4`#cite-note-fortran66-4]`_`f] From Fortran 90 onwards, the language was described using a variant of BNF.`:cite-ref-fortran95-5-0[`F5bf`_`[5`#cite-note-fortran95-5]`_`f]
• Cobol used a two-dimensional metalanguage.`:cite-ref-cobol1959-6-0[`F5bf`_`[6`#cite-note-cobol1959-6]`_`f]
• Pascal used both `F33f`_`[syntax diagrams`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Syntax_diagram]`_`f and equivalent BNF.`:cite-ref-pascal-7-0[`F5bf`_`[7`#cite-note-pascal-7]`_`f]
BNF uses recursion to express repetition, so various `F33f`_`[extensions`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Extended_Backus–Naur_form]`_`f have been proposed to allow direct indication of repetition.
>>>Statements and keywords
Some programming language grammars `F33f`_`[reserve keywords`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Reserved_word]`_`f or `F33f`_`[mark them specially`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Stropping_(syntax)]`_`f, and do not allow them to be used as `F33f`_`[identifiers`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Identifier_(computer_languages)]`_`f. This often leads to `F33f`_`[grammars`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Formal_grammar]`_`f which are easier to `F33f`_`[parse`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Parsing]`_`f, requiring less `F33f`_`[lookahead`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Parsing]`_`f.
>>>>No distinguished keywords
Fortran and PL/1 do not have reserved keywords, allowing statements like:
• in PL/1:
• `B100`F9d9IF IF = THEN THEN ...`f`b (the second `B100`F9d9IF`f`b and the first `B100`F9d9THEN`f`b are variables).
• in Fortran:
• `B100`F9d9IF (A) X = 10... `f`b conditional statement (with other variants)
• `B100`F9d9IF (A) = 2 `f`b assignment to a subscripted variable named `B100`F9d9IF`f`b
As spaces were optional up to Fortran 95, a typo could completely change the meaning of a statement: `B100`F9d9DO 10 I = 1,5 `f`b start of a loop with I running from 1 to 5 `B100`F9d9DO 10 I = 1.5 `f`b assignment of the value 1.5 to the variable `B100`F9d9DO10I`f`b
>>>>Flagged words
In Algol 60 and Algol 68, special tokens were distinguished explicitly: for publication, in boldface e.g. `B100`F9d9`!begin`!`f`b; for programming, with some special marking, e.g., a flag (`B100`F9d9'begin`f`b), quotation marks (`B100`F9d9'begin'`f`b), or underlined (`B100`F9d9begin`f`b on the `F33f`_`[Elliott 503`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Elliott_503]`_`f). This is called "stropping".
Tokens that are part of the language syntax thus do not conflict with programmer-defined names.
>>>>Reserved keywords
Certain names are reserved as part of the programming language and can not be used as programmer-defined names. The majority of the most popular programming languages use reserved keywords. Early examples include `F33f`_`[FLOW-MATIC`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=FLOW-MATIC]`_`f (1953) and `F33f`_`[COBOL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=COBOL]`_`f (1959). Since 1970 other examples include Ada, C, C++, Java, and Pascal. The number of reserved words depends on the language: C has about 30 while COBOL has about 400.
>>Semantics
Semantics is concerned with the meaning of a program. The standards documents for many programming languages use BNF or some equivalent to express the syntax/grammar in a fairly formal and precise way, but the semantics/meaning of the program is generally described using examples and English prose. This can result in ambiguity.`:cite-ref-trouble-8-0[`F5bf`_`[8`#cite-note-trouble-8]`_`f] In some language descriptions the meaning of compound statements is defined by the use of 'simpler' constructions, e.g. a while loop can be defined by a combination of tests, jumps, and `F33f`_`[labels`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Label_(computer_science)]`_`f, using `B100`F9d9if`f`b and `B100`F9d9goto`f`b.
The `F33f`_`[semantics`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Semantics_(computer_science)]`_`f article describes several mathematical/logical formalisms which have been used to specify semantics in a precise way; these are generally more complicated than BNF, and no single approach is generally accepted as the way to go. Some approaches effectively define an interpreter for the language, some use formal logic to reason about a program, some attach affixes to syntactic entities to ensure consistency, etc.
>>Expressions
A distinction is often made between statements, which are executed, and `F33f`_`[expressions`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Expression_(programming)]`_`f, which are evaluated. Expressions always evaluate to a value, which statements do not. However, expressions are often used as part of a larger statement.
In most programming languages, a statement can consist of little more than an expression, usually by following the expression with a statement terminator (semicolon). In such a case, while the expression evaluates to a value, the complete statement does not (the expression's value is discarded). For instance, in C, C++, C#, and many similar languages, `B100`F9d9x = y + 1`f`b is an expression that will set x to the value of y plus one, and the whole expression itself will evaluate to the same value that x is set to. However, `B100`F9d9x = y + 1;`f`b (note the semicolon at the end) is a statement that will still set x to the value of y plus one because the expression within the statement is still evaluated, but the result of the expression is discarded, and the statement itself does not evaluate to any value.`:cite-ref-9[`F5bf`_`[9`#cite-note-9]`_`f]
Expressions can also be contained within other expressions. For instance, the expression `B100`F9d9x = y + 1`f`b contains the expression `B100`F9d9y + 1`f`b, which in turn contains the values `B100`F9d9y`f`b and `B100`F9d91`f`b, which are also technically expressions.
Although the previous examples show assignment expressions, some languages do not implement assignment as an expression, but rather as a statement. A notable example of this is `F33f`_`[Python`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Python_(Programming_Language)]`_`f, where = is not an operator, but rather just a separator in the assignment statement. Although Python allows multiple assignments as each assignment were an expression, this is simply a special case of the assignment statement built into the language grammar rather than a true expression.`:cite-ref-10[`F5bf`_`[10`#cite-note-10]`_`f]
>>Extensibility
Most languages have a fixed set of statements defined by the language, but there have been experiments with `F33f`_`[extensible languages`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Extensible_languages]`_`f that allow the programmer to define new statements.
>>See also
• `F33f`_`[Comparison of programming languages (syntax) § Statements`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Comparison_of_programming_languages_(syntax)]`_`f
• `F33f`_`[Control flow`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Control_flow]`_`f
>>References
`:cite-note-1`!1.`! `F0af`_`[↑`#cite-ref-1]`_`f "statement". webopedia. September 1996. Retrieved 2015-03-03.
`:cite-note-algol60-2`!2.`! `F0af`_`[↑`#cite-ref-algol60-2-0]`_`f `:citerefbackusbauergreenkatz`aBackus, J.W.; Bauer, F.L.; Green, J.; Katz, C.; McCarthy, J.; Naur, P.; Perlis, A.J.; Rutishauser, H.; Samuelson, K.; Vauquois, B.; Wegstein, J.H.; van Wijngaarden, A.; Woodger, M. Naur, Peter (ed.). "Revised Report on the Algorithmic Language Algol 60". `*mass:werk`*. Section "4.1". Retrieved January 23, 2021.
`:cite-note-algol60rpt-3`!3.`! `F0af`_`[↑`#cite-ref-algol60rpt-3-0]`_`f `:citerefbackusbauergreenkatz`aBackus, J.W.; Bauer, F.L.; Green, J.; Katz, C.; McCarthy, J.; Naur, P.; Perlis, A.J.; Rutishauser, H.; Samuelson, K.; Vauquois, B.; Wegstein, J.H.; van Wijngaarden, A.; Woodger, M. Naur, Peter (ed.). "Revised Report on the Algorithmic Language Algol 60". `*mass:werk`*. Section "1.1". Retrieved January 23, 2021.
`:cite-note-fortran66-4`!4.`! `F0af`_`[↑`#cite-ref-fortran66-4-0]`_`f "FORTRAN" (PDF). United States of America Standards Institute. 1966. Retrieved February 19, 2021 – via WG5 Fortran Standards.
`:cite-note-fortran95-5`!5.`! `F0af`_`[↑`#cite-ref-fortran95-5-0]`_`f "Working draft J3/04-007" (PDF). J3 Fortran. May 10, 2004. Retrieved February 19, 2021.
`:cite-note-cobol1959-6`!6.`! `F0af`_`[↑`#cite-ref-cobol1959-6-0]`_`f "ASCII COBOL Programming Reference Manual" (PDF). unisys. June 2010. Retrieved January 23, 2021.
`:cite-note-pascal-7`!7.`! `F0af`_`[↑`#cite-ref-pascal-7-0]`_`f `:citerefjensenwirth1974`aJensen, Kathleen; Wirth, Niklaus (1974). Goos, G.; Hartmanis, J. (eds.). "PASCAL User Manual and Report" (PDF). `*Lecture Notes in Computer Science`*. Appendix D. Retrieved February 19, 2021.
`:cite-note-trouble-8`!8.`! `F0af`_`[↑`#cite-ref-trouble-8-0]`_`f `:citerefknuth1967`aKnuth, D. E. (Jul 1967). "The Remaining Trouble Spots in Algol 60" (PDF). `*The ALGOL Family`*. Retrieved February 24, 2021.
`:cite-note-9`!9.`! `F0af`_`[↑`#cite-ref-9]`_`f "ISO/IEC 9899:1999 (E)" (PDF). `*ISO/IEC`*. Archived (PDF) from the original on Feb 7, 2024.
`:cite-note-10`!10.`! `F0af`_`[↑`#cite-ref-10]`_`f "7. Simple statements". `*Python 3.10.8 documentation`*.
>>External links
• PC ENCYCLOPEDIA: Definition of: program statement
`c`F0af`_`[↑ Back to top`#top]`_`f`a